//
//  CenterHeaderView.m
//  AAIM
//
//  Created by 远的小布丁 on 2019/11/26.
//  Copyright © 2019 AAIM. All rights reserved.
//

#import "CenterHeaderView.h"

@implementation CenterHeaderView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self SetUi];
    }
    return self;
}

- (void)SetUi{
    [self addSubview:self.headImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.accountLabel];
    [self addSubview:self.moreImageView];
    self.backgroundColor = [UIColor whiteColor];
    [self setMasonry];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    NSString * headUrl = dataDic[@"data"][@"head"];
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]] placeholderImage:[UIImage imageNamed:@"bg_pyqtx"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        KWeakSelf;
        if (!error) {
            weakSelf.headImageView.image = image;
        }else
        {
            weakSelf.headImageView.image = kHeadPlaceholderImage;
        }
        }];
    [_headImageView setContentScaleFactor:[[UIScreen mainScreen] scale]];
    _headImageView.contentMode =  UIViewContentModeScaleAspectFill;
    _nameLabel.text = dataDic[@"data"][@"nickname"];
    _accountLabel.text = [NSString stringWithFormat:@"账号：%@",dataDic[@"data"][@"userName"]];
    
}

- (void)setMasonry{
    
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(SCALAE_WIDTH(20));
        make.bottom.equalTo(self.mas_bottom).offset(SCALAE_WIDTH(-36));
        make.size.mas_equalTo(CGSizeMake(SCALAE_WIDTH(65), SCALAE_WIDTH(65)));
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(SCALAE_WIDTH(10));
        make.top.equalTo(self.headImageView).offset(SCALAE_WIDTH(5));
        
    }];
    [_accountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImageView.mas_right).offset(SCALAE_WIDTH(10));
        make.top.equalTo(self.nameLabel.mas_bottom).offset(SCALAE_WIDTH(14));
        make.width.mas_equalTo(SCREEN_WIDTH- SCALAE_WIDTH(125));
    }];
    
    [_moreImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.accountLabel);
        make.right.equalTo(self.mas_right).offset(SCALAE_WIDTH(-15));
        make.size.mas_equalTo(CGSizeMake(SCALAE_WIDTH(8), SCALAE_WIDTH(13)));
    }];
}


- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:19];
        _nameLabel.textColor = KHEXCOLOR(@"#262B2F");
       
    }
    return _nameLabel;
}

- (UIImageView *)headImageView{
    if (!_headImageView) {
        _headImageView = [[UIImageView alloc]init];
        _headImageView.layer.cornerRadius = SCALAE_WIDTH(65)/2;
        _headImageView.layer.masksToBounds = YES;
        _headImageView.userInteractionEnabled = YES;
    }
    return _headImageView;
}

- (UILabel *)accountLabel{
    if (!_accountLabel) {
        _accountLabel = [[UILabel alloc]init];
        _accountLabel.font = kMainFont(13);
        _accountLabel.textColor = KHEXCOLOR(@"#262B2F");
        
    }
    return _accountLabel;
}

- (UIImageView *)moreImageView{
    if (!_moreImageView) {
        _moreImageView = [[UIImageView alloc]init];
        _moreImageView.image = [UIImage imageNamed:@"我的-返回键头"];
        _moreImageView.userInteractionEnabled = YES;
       
    }
    return _moreImageView;
}

@end
